﻿using System;
using System.Drawing;
using System.Diagnostics;

using iPhoneUI.Shell;

namespace iPhoneUI.Widgets
{
    public abstract class TextWidget : Widget
    {
        private Font m_font;

        public TextWidget()
        {
            ForeColor = Color.White;
            Font = ShellConfig.CreateFont(9, FontStyle.Regular);
        }

        public Font Font
        {
            get
            {
                return m_font;
            }
            set
            {
                m_font.SafeDispose();
                Debug.Assert(value != null);
                m_font = value;
            }
        }

        public Color ForeColor { get; set; }

        public string Text { get; set; }

        protected override void OnDispose()
        {
            m_font.SafeDispose();

            base.OnDispose();
        }

        protected int CenterString(string s, Font font, Canvas canvas)
        {
            SizeF size = canvas.MeasureString(s, font);
            return (Size.Width / 2 - (int)size.Width / 2) + Location.X;
        }
    }
}
